/**
 * 2013-6-24 下午9:39:04 Created By niexiaoqiang
 */

package com.xiaoqiang.MtwV2ForMoblie.update;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.xiaoqiang.MtwV2ForMoblie.MainActivity;

/**
 * 下载进度对话框UI更新
 */
public class DownloadDialogHandleExtension extends Handler {

	private DownloadDialog downLoaddialog;
	private MainActivity mainActivity;

	public DownloadDialogHandleExtension(MainActivity mainActivity, DownloadDialog downLoaddialog) {
		this.mainActivity = mainActivity;
		this.downLoaddialog = downLoaddialog;
	}

	@Override
	public void handleMessage(Message msg) {
		Bundle bundle = msg.getData();
		/************* 处理mtwInfo.properties接受完成后通知主界面 ************/
		String filename = bundle.getString("filename");
		if ("MtwV2ForMoblie.apk".equals(filename)) {
			int total = bundle.getInt("filetotalsize");
			int downloadsize = bundle.getInt("currentdonwloadsize");
			if (total == downloadsize) {
				downLoaddialog.download_progressbar.incrementProgressBy(100);
				downLoaddialog.isbuttonclose = true;
				downLoaddialog.dismiss();
				mainActivity.downloadDialog = null;
				mainActivity.installnewAppApk();
			} else {
				int pro = (int) ((downloadsize / (double) total) * 100);
				downLoaddialog.download_progressbar.setProgress(pro);
			}

		}
		/*************************/
	}
}
